package com.gcl.kgsvc.service;

import com.gcl.kgsvc.entity.Person;
import com.gcl.kgsvc.repository.PersonRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.core.Neo4jTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class Neo4jService {

    @Autowired
    private Neo4jTemplate template;

    @Autowired
    private PersonRepository repo;

    public Map<String, Object> addPerson() {
        Long id = 1L;
        Person p = template.save(new Person(id, "gcl"));
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "这是一个添加节点请求的响应。");
        map.put("data", p);
        return map;
    }

    public Map<String, Object> findPerson(String name) {
        List<Person> personList = repo.findPerson(name);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "这是一个查找节点请求的响应。");
        map.put("data", personList);
        return map;
    }

    public Map<String, Object> findPersonBy(String name) {
        List<Person> personList = repo.findPersonBy(name);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "这是一个查找节点请求的响应。");
        map.put("data", personList);
        return map;
    }
}
